from rest_framework import serializers
from cart import models
from shop.models import course
from user.models import user


class course(serializers.ModelSerializer):
    class Meta:
        model = course
        fields = ['id', 'title', 'cover', 'price', 'realprice']


class usercart(serializers.ModelSerializer):
    class Meta:
        model = user
        fields = ['id', 'usercode', 'phone', 'email']


class user(serializers.ModelSerializer):
    class Meta:
        model = user
        fields = '__all__'


class cart(serializers.ModelSerializer):
    # 这里必须用外键的名字
    course = course()
    user = usercart()

    class Meta:
        model = models.cart
        fields = '__all__'


class coupon(serializers.ModelSerializer):
    class Meta:
        model = models.coupon
        fields = '__all__'


class usercoupon(serializers.ModelSerializer):
    coupon = coupon()
    user = usercart()

    class Meta:
        model = models.usercoupon
        fields = '__all__'


class order(serializers.ModelSerializer):
    class Meta:
        model = models.order
        fields = '__all__'


class orderdetail(serializers.ModelSerializer):
    class Meta:
        model = models.orderdetail
        fields = '__all__'
